#include "ustandard/ustandard_def.h"
#define UM_RUN_TIMES_START(N)\
if(1) {\
    struct timeval tv_sfksjlksf[2];\
    gettimeofday(&tv_sfksjlksf[0], NULL);\
    unsigned long times_sfksjlksf = (N);\
    while(times_sfksjlksf--) {


#define UM_RUN_TIMES_FINISH(SECOND)\
    }\
    gettimeofday(&tv_sfksjlksf[1], NULL);\
    double sec_sfksjlksf = (double)(tv_sfksjlksf[1].tv_sec - tv_sfksjlksf[0].tv_sec) + \
            (double)(tv_sfksjlksf[1].tv_usec - tv_sfksjlksf[0].tv_usec)/1e6;\
    SECOND = sec_sfksjlksf; \
}


#define PRINT_TCOST(fp)     \
    fprintf(fp, "----------cost time %lf .\n", sec);

int64_t utv_to_usec(struct timeval* tv1, struct timeval* tv2)
{
    int64_t usec = (int64_t)(tv1->tv_sec-tv2->tv_sec)*(int64_t)1000000 + (int64_t)(tv1->tv_usec-tv2->tv_usec);
    return usec;
}


int main()
{
    double sec = 0.0;
    int times = 10000000;
    //times = 1;
    struct timeval tv2 = {0, 123456};
    struct timeval tv1 = {2301, 0};
    int64_t usec;

UM_RUN_TIMES_START(times)
    usec = (int64_t)(tv1.tv_sec-tv2.tv_sec)*1000000 + (tv1.tv_usec-tv2.tv_usec);
UM_RUN_TIMES_FINISH(sec)
PRINT_TCOST(stdout)
    printf("usec=%lld\n", usec);

UM_RUN_TIMES_START(times)
    usec = (int64_t)(tv1.tv_sec-tv2.tv_sec)*(int64_t)1000000 + (int64_t)(tv1.tv_usec-tv2.tv_usec);
UM_RUN_TIMES_FINISH(sec)
PRINT_TCOST(stdout)
    printf("usec=%lld\n", usec);

UM_RUN_TIMES_START(times)
    usec = (int64_t)(tv1.tv_sec-tv2.tv_sec)*(int64_t)1e6 + (int64_t)(tv1.tv_usec-tv2.tv_usec);
UM_RUN_TIMES_FINISH(sec)
PRINT_TCOST(stdout)
    printf("usec=%lld\n", usec);

UM_RUN_TIMES_START(times)
    usec = utv_to_usec(&tv1, &tv2);
UM_RUN_TIMES_FINISH(sec)
PRINT_TCOST(stdout)
    printf("usec=%lld\n", usec);

UM_RUN_TIMES_START(times)
    usec = (tv1.tv_sec-tv2.tv_sec)*1e6 + (tv1.tv_usec-tv2.tv_usec);
UM_RUN_TIMES_FINISH(sec)
PRINT_TCOST(stdout)
    printf("usec=%lld\n", usec);

UM_RUN_TIMES_START(times)
    usec = (double)(tv1.tv_sec-tv2.tv_sec)*1e6 + (tv1.tv_usec-tv2.tv_usec);
UM_RUN_TIMES_FINISH(sec)
PRINT_TCOST(stdout)
    printf("usec=%lld\n", usec);

UM_RUN_TIMES_START(times)
    usec = (int64_t)((double)(tv1.tv_sec-tv2.tv_sec)*1e6 + (double)(tv1.tv_usec-tv2.tv_usec));
UM_RUN_TIMES_FINISH(sec)
PRINT_TCOST(stdout)
    printf("usec=%lld\n", usec);





    return 0;
}
